<template>
	<view class="container">
		<view class="section">
			<input v-model="adminname" placeholder="店长账号" />
		</view>
		<view class="section">
			<input v-model="password" password="true" placeholder="密码" />
		</view>
		<button class="login-btn" type="primary" @click="login">登录</button>
	</view>
</template>

<script>
	let _self;
	export default {
		data() {
			return {
				adminname: '',
				password: '',
			};
		},
		methods: {
			login() {
				const {
					adminname,
					password
				} = this
				if (!adminname) {
					uni.showModal({
						content: '请填写用户名',
						showCancel: false
					})
					return
				}
				if (!password) {
					uni.showModal({
						content: '请填写密码',
						showCancel: false
					})
					return
				}
				uni.showLoading({
					title: '登录中...'
				})
				uniCloud.callFunction({
					name: 'login_admin',
					data: {
						name:adminname,
						pwd:password,
					},
					success: (res) => {
						uni.hideLoading();
						//console.log(res.result);
						if(res.result.code == 0){
							uni.showToast({
								title: res.result.msg,
								//icon: 'none'
							})
							this.$util.navigateTo('../data/data')
							uni.setStorageSync('admintoken', res.result.token)
							uni.setStorageSync('adminname', this.adminname)
						}else if(res.result.code == -2){
							uni.showToast({
								title: res.result.msg,
								icon: 'none'
							})
						}
					},
					fail: (err) => {
						console.log(err);
						uni.showToast({
							title: '登陆失败，请稍后重试',
							//icon: 'none'
						})
					},
					complete: (c) => {
						//console.log(c)
					}
				})/* .then((res) => {
					uni.hideLoading()
					if (res.result.token) {
						uni.showToast({
							title: '登录成功',
							icon: 'none'
						})
						uni.setStorageSync('token', res.result.token)
						uni.switchTab({
							url: '/pages/index/index'
						})
					} else {
						return Promise.reject(new Error(res.result.msg))
					}
				}).catch((err) => {
					uni.hideLoading()
					uni.showModal({
						content: err.message || '登录失败',
						showCancel: false
					})
				}) */
			}
		}
	}
</script>

<style scoped>
	.container {
		padding: 30px;
	}

	.section {
		margin: 20px;
		padding: 10px 0px;
		border-bottom: 2upx solid #eee;
	}

	.login-btn {
		font-size:36rpx;
		text-align:center;
		color:white;
		background-color:#0055ff;
		height: 80rpx;
		line-height: 80rpx;
		width:500rpx;
	}
</style>